package com.java.springcloud.config;

import cn.hutool.core.date.DateUtil;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;

/**
 * @author dushougudu
 */
public class CustomDateDeserializer extends JsonDeserializer {
    @Override
    public Object deserialize(JsonParser parser, DeserializationContext context) throws IOException {
        return StringUtils.isEmpty(parser.getText()) ? null : DateUtil.parse(parser.getText()).toJdkDate();
    }
}
